Skip to content

Add RefasterRuleIndex for single-pass indexed Refaster rule execution. - #6430

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1030825963
Dec 4, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1030825963

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Add RefasterRuleIndex for single-pass indexed Refaster rule execution.

Applying large suites of RefasterRule instances sequentially walks the entire AST once per rule, recomputes @SuppressWarnings per rule per declaration, invokes @Matches predicates before checking UFreeIdent parameter types, and repeats reflective lookups in Template.infer. On suites with thousands of rules, AST traversal, suppression checks, and failed Unifier allocations dominate runtime.

Introduce RefasterRuleIndex to execute a collection of RefasterRule instances in a single AST pass while preserving RefasterScanner semantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical @SuppressWarnings / self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter extracted via fail-safe package-private UTree.collectRequirements hooks, dispatches ExpressionTemplate rules via fail-safe UExpression.classifyRootDispatch by (Tree.Kind, methodName) and BlockTemplate rules by first-statement (Tree.Kind, methodName) plus a required statement-kind EnumSet with wildcard fallbacks, and shares a per-compilation-unit MatchContext and VisitorState across Unifier instances. In addition, UMatches rejects incompatible UClassType parameters before invoking Matcher predicates, BlockTemplate guards first-statement kind before allocating a Unifier, and Template caches javac reflection handles. All index structures live outside serialized RefasterRule graphs so no new fields are serialized; adding package-private methods on Template and UTree classes changes their default serialVersionUID, so serialized .refaster artifacts must be compiled against the matching runtime.

Applying large suites of `RefasterRule` instances sequentially walks the entire AST once per rule, recomputes `@SuppressWarnings` per rule per declaration, invokes `@Matches` predicates before checking `UFreeIdent` parameter types, and repeats reflective lookups in `Template.infer`. On suites with thousands of rules, AST traversal, suppression checks, and failed `Unifier` allocations dominate runtime.

Introduce `RefasterRuleIndex` to execute a collection of `RefasterRule` instances in a single AST pass while preserving `RefasterScanner` semantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical `@SuppressWarnings` / self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter extracted via fail-safe package-private `UTree.collectRequirements` hooks, dispatches `ExpressionTemplate` rules via fail-safe `UExpression.classifyRootDispatch` by `(Tree.Kind, methodName)` and `BlockTemplate` rules by first-statement `(Tree.Kind, methodName)` plus a required statement-kind `EnumSet` with wildcard fallbacks, and shares a per-compilation-unit `MatchContext` and `VisitorState` across `Unifier` instances. In addition, `UMatches` rejects incompatible `UClassType` parameters before invoking `Matcher` predicates, `BlockTemplate` guards first-statement kind before allocating a `Unifier`, and `Template` caches javac reflection handles. All index structures live outside serialized `RefasterRule` graphs so no new fields are serialized; adding package-private methods on `Template` and `UTree` classes changes their default `serialVersionUID`, so serialized `.refaster` artifacts must be compiled against the matching runtime.

PiperOrigin-RevId: 1035840958
@copybara-service
copybara-service Bot merged commit 3bb7801 into master Dec 4, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the test_1030825963 branch December 4, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant